<?php
/**
 * <pre>
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT      : rubik-base
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * </pre>
 * 
 * @version 		1.0
 * @author			hoadn <hoadn@rubik.com.vn>
 * @access			public
 * @package			rubik.base.helper
 *
 * Created on	: May 15, 2008
 */

class RObjectHelper {
	
	/**
	 * Get the service JSON instance
	 *
	 * @return Services_JSON
	 */
	static function getServiceJSON() {
		static $json;
		if (empty ( $json )) {
			RLibImporter::cls( "json.Services_JSON" );
			$json = new Services_JSON ( );
		}
		return $json;
	}
	
	/**
	 * Create JSON object
	 *
	 * @param object $object
	 * @return string
	 */
	static function createJSON($object) {
		$json = RObjectHelper::getServiceJSON ();
		return $json->encode ( $object );
	}
	
	/**
	 * Convert array into objects
	 *
	 * @param array $array
	 * @return object
	 */
	static function &arrayToObject($array = array()) {
		if (! empty ( $array )) {
			$data = false;
			
			foreach ( $array as $akey => $aval ) {
				$data->{$akey} = $aval;
			}
			
			return $data;
		}
		
		return false;
	}
	
}
?>